#include "villagetile.h"
#include "playertable.h"
#include <QPainter>
#include <QStyleOption>
#include <QDebug>
/*

  VILLAGE SUPER CLASS

*/
VillageTile::VillageTile(QGraphicsObject *parent, int x, int y) :
    QGraphicsObject(parent), _x(x), _y(y)
{
    setAcceptHoverEvents(true);
    connect(this, SIGNAL(pressed(QPoint)), this, SLOT(printPos(QPoint)));
}


void VillageTile::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget){

    bool down = option->state & QStyle::State_Sunken;
    bool over = option->state & QStyle::State_MouseOver;
    if(down){
        QBrush b(QColor(Qt::white), Qt::SolidPattern);
        painter->fillRect(boundingRect(), b);
    }else if(over){
        QBrush b(QColor(Qt::black), Qt::SolidPattern);
        painter->fillRect(boundingRect(), b);
    }else{
        QBrush b(QColor(Qt::green), Qt::SolidPattern);
        painter->fillRect(boundingRect(), b);
    }
    painter->drawText(boundingRect(), Qt::AlignCenter, name());


}
QRectF VillageTile::boundingRect() const{
    int width = TileBoard::TILE_WIDTH;
    int totalWidth = 3*width;
    return QRectF(-totalWidth/2+_x*width, -totalWidth/2+_y*width, width, width);
}

QPoint VillageTile::getVillagePos(){
    return QPoint(_x, _y);
}

void VillageTile::access(){
    shopDialog->enter();
}
void VillageTile::mousePressEvent(QGraphicsSceneMouseEvent *event){
    emit pressed(this);
    emit pressed(getVillagePos());
    update();
}

void VillageTile::mouseReleaseEvent(QGraphicsSceneMouseEvent *event){
    update();
}

void VillageTile::startAshop(VillageTile*){
    access();
}

void VillageTile::printPos(QPoint p){
    qDebug() << p;
}

/*


  TEA SHOP CLASS


*/

TeashopTile::TeashopTile(QGraphicsObject *parent, int x, int y):
    VillageTile(parent,x, y)
{
    shopDialog = new TeashopDialog(parent, QPixmap(":/common/images/shopGirl.png"));
    //the dialog should be over village tiles
}



QString TeashopTile::name(){
    return "Tea";
}

/*


  SORCERER SHOP CLASS


*/

SorcererTile::SorcererTile(QGraphicsObject *parent, int x, int y):
    VillageTile(parent,x, y)
{
    shopDialog = new SorcererDialog(parent, QPixmap(":/common/images/shopGirl.png"));
    //the dialog should be over village tiles
}

QString SorcererTile::name(){
    return "Sorcerer";
}


/*


  ALTAR SHOP CLASS



  */


AltarTile::AltarTile(QGraphicsObject *parent, int x, int y):
    VillageTile(parent,x, y)
{
    shopDialog = new AltarDialog(parent, QPixmap(":/common/images/shopGirl.png"));
    //the dialog should be over village tiles
}



QString AltarTile::name(){
    return "Altar";
}

/*


  PAVILION SHOP CLASS



  */


PavilionTile::PavilionTile(QGraphicsObject *parent, int x, int y):
    VillageTile(parent,x, y)
{
    shopDialog = new PavilionDialog(parent, QPixmap(":/common/images/shopGirl.png"));
    //the dialog should be over village tiles
}



QString PavilionTile::name(){
    return "Pavilion";
}
